package helperClassSearch;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class CreateSuggest {
	public static void CreateSuggestClass(int[] sheetNumbers, String fileName, String packageName, String className) {
		File replacedFile = new File(fileName);
		replacedFile.delete();

		try {
			Workbook workbook = Workbook.getWorkbook(new File("C:\\Documents and Settings\\Administrator\\My Documents\\Dropbox\\CTA\\XLS\\CTA.xls"));
			FileWriter fstream = new FileWriter(fileName);
			BufferedWriter textFile = new BufferedWriter(fstream);

			textFile.write("package com.cyclingthealps." + packageName + ";\n");
			textFile.write("\n");
			textFile.write("import com.cyclingthealps.client.planned.MyMessagesPlanned;\n");
			textFile.write("import com.cyclingthealps.client.protour.MyMessagesProTour;\n");
			textFile.write("import com.cyclingthealps.client.climbs.MyMessagesClimbs;\n");
			textFile.write("import com.google.gwt.core.client.GWT;\n");
			textFile.write("import com.google.gwt.user.client.ui.MultiWordSuggestOracle;\n");
			textFile.write("\n");
			textFile.write("public class SuggestBox {\n");
			textFile.write("public static MyMessages res = (MyMessages) GWT.create(MyMessages.class);\n");
			textFile.write("public static MyMessagesPlanned resPlanned = (MyMessagesPlanned) GWT.create(MyMessagesPlanned.class);\n");
			textFile.write("public static MyMessagesProTour resProTour = (MyMessagesProTour) GWT.create(MyMessagesProTour.class);\n");
			textFile.write("public static MyMessagesClimbs resClimbs = (MyMessagesClimbs) GWT.create(MyMessagesClimbs.class);\n");
			textFile.write("\n");
			textFile.write("public static MultiWordSuggestOracle results() {\n");
			textFile.write("MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(); \n");
			textFile.write("\n");

			for (int d = 0; d < sheetNumbers.length; d++) {
				Sheet sheet = workbook.getSheet(sheetNumbers[d]);
				Cell[] count = sheet.getColumn(0);
				String resources;
				if (sheetNumbers[d] == 0 || sheetNumbers[d] == 1 || sheetNumbers[d] == 2 || sheetNumbers[d] == 3) {
					resources = "res.";
				}

				else{
					if (sheetNumbers[d] == 10) {
						resources = "resMountains.";
					}
					else{
						if (sheetNumbers[d] == 17) {
							resources = "resClimbs.";
						}
						else {
							resources = "resPlanned.";	
						}
					}
				
				}
				for (int i = 1; i < count.length; i++) {
					Cell passOracleCell = sheet.getCell(40, i);
					String oracle = passOracleCell.getContents();
					System.out.println(oracle);
					textFile.write("oracle.add(" + resources + "" + oracle + "()");
					textFile.write(");\n");
				}
				
//				for (int j = 1; j < count.length; j++) {
//					Cell passOracleCell = sheet.getCell(40, j);
//					String oracle = passOracleCell.getContents();
//					System.out.println(oracle);
//					textFile.write("oracle.add(" + resources + "");
//					textFile.write(oracle + "() + \" \" + res.OverviewOracle()");
//					textFile.write(");\n");
//				}
				
//				if (sheetNumbers[d] == 0 || sheetNumbers[d] == 1 || sheetNumbers[d] == 2 || sheetNumbers[d] == 3) {
//					for (int j = 1; j < count.length; j++) {
//						Cell passOracleCell = sheet.getCell(40, j);
//						String oracle = passOracleCell.getContents();
//						System.out.println(oracle);
//						textFile.write("oracle.add(" + resources + "");
//						textFile.write(oracle + "() + \" Video");
//						textFile.write("\");\n");
//					}
//				}
//				if (sheetNumbers[d] == 0 || sheetNumbers[d] == 1 || sheetNumbers[d] == 2 || sheetNumbers[d] == 3) {
//					for (int j = 1; j < count.length; j++) {
//						Cell passOracleCell = sheet.getCell(40, j);
//						String oracle = passOracleCell.getContents();
//						System.out.println(oracle);
//						textFile.write("oracle.add(" + resources + "");
//						textFile.write(oracle + "() + \" Slideshow");
//						textFile.write("\");\n");
//					}
//				}

				for (int j = 1; j < count.length; j++) {
					Cell passOracleCell = sheet.getCell(40, j);
					String oracle = passOracleCell.getContents();
					System.out.println(oracle);
					textFile.write("oracle.add(" + resources + "");
					textFile.write(oracle + "() + \" 3D Tour");
					textFile.write("\");\n");
				}
				for (int j = 1; j < count.length; j++) {
					Cell passOracleCell = sheet.getCell(40, j);
					String oracle = passOracleCell.getContents();
					System.out.println(oracle);
					textFile.write("oracle.add(" + resources + "");
					textFile.write(oracle + "() + \" Game");
					textFile.write("\");\n");
				}
//				for (int j = 1; j < count.length; j++) {
//					Cell passOracleCell = sheet.getCell(40, j);
//					String oracle = passOracleCell.getContents();
//					System.out.println(oracle);
//					textFile.write("oracle.add(" + resources + "");
//					textFile.write(oracle + "() + \" Profile");
//					textFile.write("\");\n");
//				}
				for (int j = 1; j < count.length; j++) {
					Cell passOracleCell = sheet.getCell(40, j);
					String oracle = passOracleCell.getContents();
					System.out.println(oracle);
					Cell streetviewTour = sheet.getCell(45, j);
					String streetview = streetviewTour.getContents();
					if (!streetview.endsWith("NOP")) {
						textFile.write("oracle.add(" + resources + "");
						textFile.write(oracle + "() + \" Streetview");
						textFile.write("\");\n");
					}
				}
				for (int j = 1; j < count.length; j++) {
					Cell passOracleCell = sheet.getCell(40, j);
					String oracle = passOracleCell.getContents();
					System.out.println(oracle);
					Cell panoramaCell = sheet.getCell(51, j);
					String panorama = panoramaCell.getContents();
					if (!panorama.endsWith("NOP")) {
						textFile.write("oracle.add(" + resources + "");
						textFile.write(oracle + "() + \" Panorama");
						textFile.write("\");\n");
					}
				}
//				for (int j = 1; j < count.length; j++) {
//					Cell passOracleCell = sheet.getCell(40, j);
//					String oracle = passOracleCell.getContents();
//					System.out.println(oracle);
//					textFile.write("oracle.add(" + resources + "");
//					textFile.write(oracle + "() + \" Explore");
//					textFile.write("\");\n");
//				}

			}
			textFile.write("return oracle;\n");
			textFile.write("}\n");
			textFile.write("}\n");
			textFile.write("\n");
			textFile.close();
		} catch (BiffException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
